package com.ruoyi.webshop.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.webshop.domain.GoodsSkuInfo;
import com.ruoyi.webshop.service.IGoodsSkuInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品细分Controller
 * 
 * @author ruoyi
 * @date 2024-03-17
 */
@RestController
@RequestMapping("/webshop/GoodsSkuInfo")
public class GoodsSkuInfoController extends BaseController
{
    @Autowired
    private IGoodsSkuInfoService goodsSkuInfoService;

    /**
     * 查询商品细分列表
     */
    @PreAuthorize("@ss.hasPermi('webshop:GoodsSkuInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(GoodsSkuInfo goodsSkuInfo)
    {
        startPage();
        List<GoodsSkuInfo> list = goodsSkuInfoService.selectGoodsSkuInfoList(goodsSkuInfo);
        return getDataTable(list);
    }

    /**
     * 导出商品细分列表
     */
    @PreAuthorize("@ss.hasPermi('webshop:GoodsSkuInfo:export')")
    @Log(title = "商品细分", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GoodsSkuInfo goodsSkuInfo)
    {
        List<GoodsSkuInfo> list = goodsSkuInfoService.selectGoodsSkuInfoList(goodsSkuInfo);
        ExcelUtil<GoodsSkuInfo> util = new ExcelUtil<GoodsSkuInfo>(GoodsSkuInfo.class);
        util.exportExcel(response, list, "商品细分数据");
    }

    /**
     * 获取商品细分详细信息
     */
    @PreAuthorize("@ss.hasPermi('webshop:GoodsSkuInfo:query')")
    @GetMapping(value = "/{skuId}")
    public AjaxResult getInfo(@PathVariable("skuId") Long skuId)
    {
        return success(goodsSkuInfoService.selectGoodsSkuInfoBySkuId(skuId));
    }

    /**
     * 新增商品细分
     */
    @PreAuthorize("@ss.hasPermi('webshop:GoodsSkuInfo:add')")
    @Log(title = "商品细分", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GoodsSkuInfo goodsSkuInfo)
    {
        return toAjax(goodsSkuInfoService.insertGoodsSkuInfo(goodsSkuInfo));
    }

    /**
     * 修改商品细分
     */
    @PreAuthorize("@ss.hasPermi('webshop:GoodsSkuInfo:edit')")
    @Log(title = "商品细分", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GoodsSkuInfo goodsSkuInfo)
    {
        return toAjax(goodsSkuInfoService.updateGoodsSkuInfo(goodsSkuInfo));
    }

    /**
     * 删除商品细分
     */
    @PreAuthorize("@ss.hasPermi('webshop:GoodsSkuInfo:remove')")
    @Log(title = "商品细分", businessType = BusinessType.DELETE)
	@DeleteMapping("/{skuIds}")
    public AjaxResult remove(@PathVariable Long[] skuIds)
    {
        return toAjax(goodsSkuInfoService.deleteGoodsSkuInfoBySkuIds(skuIds));
    }


}
